/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_kernel.htm
 *
 * Zhiqim Kernel is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.kernel.model.seqs;

import org.zhiqim.kernel.util.DateTimes;

/**
 * 整型序列值，默认从1从0x7FFFFFFF(最大值)，每天重新开始<br><br>
 * 1、最小值必须>=1<br>
 * 2、如果设置最大值，则最大值必须大小最小值，否则取整数最大值0x7FFFFFFF
 * 
 * @version v1.0.0 @author zouzhigang 2014-2-27 新建与整理
 */
public class SequenceDate extends Sequence
{
    private String date = DateTimes.getDateString();
    
    /** 从1到0x7FFFFFFF */
    public SequenceDate()
    {
    }
    
    /** 从1到len个9 */
    public SequenceDate(int len)
    {
        super(len);
    }
    
    /** 从min到max */
    public SequenceDate(long min, long max)
    {
        super(min, max);
    }
    
    /** 从min到max，指定初始值 */
    public SequenceDate(long min, long max, long seq)
    {
        super(min, max, seq);
    }
    
    public String getDate()
    {
        return date;
    }
    
    /********************************************************************/
    //重写获取方法，按天判断
    /********************************************************************/
    
    @Override
    public long next()
    {
        synchronized (this)
        {
            String curDate = DateTimes.getDateString();
            if (curDate.equals(date)){
                chkSequence();
            }else{
                resetSequence();
                date = curDate;
            }
            
            return sequence++;
        }
    }
}
